import config from '../config/config';
import request from '../utils/request';

let service = {};

service.createOrder = (param, cb) => {
    param = param || {};

    let requestUrl = config.api.createOrder;
    request({
        url: requestUrl,
        data: param,
        showLoading:true,
        method: 'POST',
        success: res => {
            cb(res);
        },
        fail: res => {
        }
    });
};

service.payOrder = (param, cb, ca) => {
    param = param || {};

    let requestUrl = config.api.payOrder;
    request({
        url: requestUrl,
        data: param,
        showLoading:true,
        method: 'POST',
        success: res => {
            cb(res);
        },
        fail: res => {
        },
        complete: res => {
          if (ca && (typeof ca) == 'function') {
            ca(res);
          }
        }
    });
};

service.linMoney = (param, cb, ca) => {
  param = param || {};

  request({
    url: config.api.linMoney,
    data: param,
    method: 'GET',
    success: res => {
      cb(res);
    },
    complete: res => {
      if (ca && (typeof ca) == 'function') {
        ca(res);
      }
    }
  });
}

//红包列表
service.redpack = (param, cb) => {
  param = param || {};

  let requestUrl = config.api.redpack;
  request({
    url: requestUrl,
    data: param,
    showLoading: true,
    method: 'GET',
    success: res => {
      cb(res);
    },
    fail: res => {
    }
  });
};

//获取买家支付订单数量
service.joinactive = (param, cb) => {
  param = param || {};

  let requestUrl = config.api.joinactive;
  request({
    url: requestUrl,
    data: param,
    // showLoading: true,
    method: 'GET',
    success: res => {
      cb(res);
    },
    fail: res => {
    }
  });
};

//优惠券码兑换优惠券
service.codeconvert = (param, cb) => {
  param = param || {};

  let requestUrl = config.api.codeconvert;
  request({
    url: requestUrl,
    data: param,
    showLoading: true,
    method: 'POST',
    success: res => {
      cb(res);
    },
    fail: res => {
    }
  });
};

// 创建群接龙订单
service.create_solitaire_order = (param, cb) => {
  param = param || {};

  let requestUrl = config.api.create_solitaire_order;
  request({
    url: requestUrl,
    data: param,
    showLoading: true,
    method: 'POST',
    success: res => {
      cb(res);
    },
    fail: res => {
    }
  });
};

// 支付群接龙订单
service.pay_solitaire_order = (param, cb) => {
  param = param || {};

  let requestUrl = config.api.pay_solitaire_order;
  request({
    url: requestUrl,
    data: param,
    showLoading: true,
    method: 'POST',
    success: res => {
      cb(res);
    },
    fail: res => {
    }
  });
};

// 连续签到7天且24小时内下单奖励
service.ifsignsuccess = (param, cb) => {
  param = param || {};

  let requestUrl = config.api.ifsignsuccess;
  request({
    url: requestUrl,
    data: param,
    showLoading: true,
    method: 'GET',
    success: res => {
      cb(res);
    },
    fail: res => {
    }
  });
};

//创建正式砍价订单
service.create_bargain_order = (param, cb) => {
  param = param || {};

  let requestUrl = config.api.create_bargain_order;
  request({
    url: requestUrl,
    data: param,
    showLoading: true,
    method: 'POST',
    success: res => {
      cb(res);
    },
    fail: res => {
    }
  });
};
//支付砍价订单
service.pay_bargain_order = (param, cb) => {
  param = param || {};

  let requestUrl = config.api.pay_bargain_order;
  request({
    url: requestUrl,
    data: param,
    showLoading: true,
    method: 'POST',
    success: res => {
      cb(res);
    },
    fail: res => {
    }
  });
};

//获取订单页面的余额抵现金额
service.customerbalance = (param, cb) => {
  param = param || {};

  let requestUrl = config.api.customerbalance;
  request({
    url: requestUrl,
    data: param,
    // showLoading: true,
    method: 'GET',
    success: res => {
      cb(res);
    },
    fail: res => {
    }
  });
};

//获取当前身份证号码
service.user_id_card = (param, cb) => {
  param = param || {};

  let requestUrl = config.api.user_id_card;
  request({
    url: requestUrl,
    data: param,
    // showLoading: true,
    method: 'GET',
    success: res => {
      cb(res);
    },
    fail: res => {
    }
  });
};

module.exports = service;